<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
	<%
	
		List<ServiceType> typeList = null;
		if(request.getAttribute("serviceTypeList")!=null){
			typeList = (List)request.getAttribute("serviceTypeList");
		}
	
	%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="java.util.List"%>
<%@page import="com.doone.telmarket.domain.ibator.ServiceType"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link rel="stylesheet" rev="stylesheet"
	href="${pageContext.request.contextPath}/css/admin/style-admin.css"
	type="text/css" media="all" />
<script type="text/javascript"
	src="${pageContext.request.contextPath}/ckeditor/ckeditor.js"></script>

<script src="${pageContext.request.contextPath}/js/jquery.js"
	type="text/javascript"></script>
<script
	src="${pageContext.request.contextPath}/js/jquery.ui.draggable.js"
	type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/js/jquery.alerts.js"
	type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/js/ajaxfileupload.js"
	type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/js/common.js"
	type="text/javascript"></script>
<link href="${pageContext.request.contextPath}/css/jquery.alerts.css"
	rel="stylesheet" type="text/css" media="screen" />
	
	<script type="text/javascript">
		function add(){
			var sel = document.getElementById("select1");
			for(var i=0;i<sel.length;i++) {
			     if(sel.options[i].selected) {
			       var option = document.createElement("option");
			       option.value = sel.options[i].value;
			       option.innerHTML = sel.options[i].text;
			       var select2 = document.getElementById("select2");
			       if(select2.length<4){
			    	   select2.appendChild(option);
			    	   sel.removeChild(sel.options[i]);
				   }else{
						jAlert("只能推荐四个热门业务","消息");
						return;
				   }
			       
			     }
			  } 
						
		}

		function del(){
			var sel = document.getElementById("select2");
			for(var i=0;i<sel.length;i++) {
			     if(sel.options[i].selected) {
			       var option = document.createElement("option");
			       option.value = sel.options[i].value;
			       option.innerHTML = sel.options[i].text;
			       var select2 = document.getElementById("select1");
			    	select2.appendChild(option);
			    	sel.removeChild(sel.options[i]);
			     }
			  } 

		}

		function getProductByType(typeName){
			$.ajax({
			    url: document.getElementById("contextPath").value+'/admin/getProductByTypeName',
			    type: 'POST',
			    data: "serviceTypeName="+typeName,
			    timeout: 15000,
			    error: function(){
			    	jAlert('获取数据失败','消息');
			    },
			    success: function(msg){
			    	if(msg=="F"){
			    		jAlert('系统繁忙,请你稍候再试','消息');
					}else{
						eval('var obj='+msg);
						 document.getElementById("select1").length = 0;
						 document.getElementById("select2").length = 0;
						for(var i=0;i<obj.length;i++){
							var option = document.createElement("option");
						    option.value = obj[i].service.serviceCode+"~"+obj[i].productId+"~"+typeName;
						    option.innerHTML = obj[i].productName;
						    document.getElementById("select1").appendChild(option);
						}
					}
			    }
			});
		}

		function submitForm(){
			var sel = document.getElementById("select2");
			if(sel.length<1){
				jAlert('请至少推荐一个热门业务','消息');
				return;
			}else{
				var arry = sel.options[0].value.split("~");
				var typeName = arry[2];
				$.ajax({
				    url: document.getElementById("contextPath").value+'/admin/deleteHotBusi',
				    type: 'POST',
				    data: "serviceTypeName="+typeName,
				    timeout: 15000,
				    error: function(){
				    	jAlert('删除数据失败','消息');
				    },
				    success: function(msg){
				    	jAlert(msg,'消息');
				    	if(msg=="删除数据成功"){
					    		for(var i=0;i<sel.length;i++){
								       var pram = sel.options[i].value.split("~");
								       var serviceCode = pram[0];
								       var productid = pram[1];
										$.ajax({
											    url: document.getElementById("contextPath").value+'/admin/saveIndexHotBusi',
											    type: 'POST',
											    data: "serviceCode="+serviceCode+"&productId="+productid+"&orderid="+i+"&serviceTypeName="+typeName,
											    timeout: 15000,
											    error: function(){
											    	jAlert('保存失败','消息');
											    },
											    success: function(msg){
											    	jAlert(msg,'消息');
											    	if(msg!="保存失败"){
											    		document.getElementById("select1").length = 0;
														document.getElementById("select2").length = 0;
													    }
											    }
											});
								 }
						}else{
							jAlert(msg,'消息');
						}
				    }
				});
							
			}
		}
	
	
	</script>
</head>
<body class="ContentBody"><input type="hidden" id="contextPath" value="${pageContext.request.contextPath}">
<div style="z-index: 1;height: 1000">

<div class="MainDiv"><input  type="hidden"  id="contextPath" value="${pageContext.request.contextPath}">
<table width="99%" border="0" cellpadding="0" cellspacing="0"
	class="CContent">
	<tr>
		<th class="tablestyle_title">主页热门业务配置</th>
	</tr>
	<tr>
		<td class="CPanel">
		<table border="0" cellpadding="0" cellspacing="0" style="width: 100%">
			<tr>
				<td align="left">
				<%
					if(typeList!=null&&typeList.size()!=0){
						for(int i=0;i<typeList.size();i++){
						%>
						<a onclick="getProductByType('<%=typeList.get(i).getServiceTypeName() %>')" style="cursor: hand"><%=typeList.get(i).getServiceTypeName() %></a>
						<%
						}
					}
				%>
				</td>
			</tr>

			<tr align="center">
				<td class="TablePanel"></td>
			</tr>
			<tr>
				<TD width="100%">
				

				
				<div >
				<fieldset style="height: 100%;"><legend>增加增值业务(带*的为必填)</legend>
		
				<table border="0" cellpadding="2" cellspacing="1"
					style="width: 100%" id="firstTable">

					<tr >
							<TD colspan="2" align="left" height="50px">
							<div style="width: 300px;float: left">
								<fieldset>
								<legend>该类别下已有产品</legend>
								
									<select multiple="multiple" id="select1" onchange="" size="20" style="width: 270px">
									
									</select>
								</fieldset>
							</div>
							<div style="width: 100px;float: left"><br><br><br>
								<input type="button" value="增加" onclick="add();" class="button"><br>
								<input type="button" value="删除" onclick="del();" class="button">
							</div>
							<div style="width: 300px;float: left">
							<form action="" id="mainForm">
								<fieldset>
								<legend>已选择产品</legend>
									<select multiple="multiple" id="select2" name="pram"  size="20"  onchange=""  style="width: 270px">
										
									</select>
								</fieldset>
								</form>
							</div>
							
								</TD>
					</tr>
					<tr>
						<TD colspan="2" align="left" height="50px"><input type="button"
							value="保存" onclick="submitForm();" class="button" /> 
						</TD>
					</tr>
				</table>
				<br />
				</fieldset>
				</div>
				
				</TD>
			</TR>
		</TABLE>
		</td>
	</tr>
	
	
</TABLE>
</div>

</div>
</body>
</html>